package br.com.vision.util.text;

import java.security.MessageDigest;

public class PasswordUtil {

	public static String convertToMD5(String senha) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] array = md.digest(senha.getBytes());
			StringBuffer sb = new StringBuffer();

			for (int i = 0; i < array.length; ++i) {
				sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
			}

			return sb.toString();
		} catch (java.security.NoSuchAlgorithmException e) {
		}
		return null;
	}

	public static String generateRandomPassword(int length) {
		return new String(CharUtils.randomCharSequence(length));
	}

}
